﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RobotBattle2.Runtime {
	public static class CallStack {
		public static ICallStackFrame GetCurrentCallStackFrame(this IVariableScope scope) {
			while (scope != null) {
				var frame = scope as ICallStackFrame;
				if (frame != null)
					return frame;
				scope = scope.ParentScope;
			}
			return null;
		}

		public static IEnumerable<ICallStackFrame> GetCallStack(this IVariableScope scope) {
			while (scope != null) {
				var frame = scope as ICallStackFrame;
				if (frame != null) 
					yield return frame;
			}
		}
	}
}
